<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/global.css" media="all">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/table.css"/>
    <title>redis数据查询</title>
    <style type="text/css">
        .searcheBottom{margin-bottom: 10px;}
    </style>
</head>
<body>
<div class="admin-main">
    <div style="margin: 15px;">
        <form class="layui-form" id="layui-form" action="">
            <blockquote class="layui-elem-quote">
                <div class="demoTable">
                    <div class="layui-inline searcheBottom">
                        KEY：
                        <div class="layui-inline">
                            <input class="layui-input" name="key" autocomplete="off" placeholder="请输入KEY"/>
                        </div>
                    </div>
                    <div class="layui-inline searcheBottom">
                        <button class="layui-btn" data-type="reload" id="search" lay-submit lay-filter="save">搜索</button>
                        <button  type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </blockquote>
            <div class="layui-inline searcheBottom" id="key">
                <span style="font-size: 16px;padding-bottom: 10px;" id="rowKeys"><b>redis数据查询</b></span>
            </div>
        </form>
    </div>
    <script type="text/javascript" src="/plugins/layui/layui.js"></script>
    <script>
        layui.use(['jquery','table','laydate','layer','form','util'],function(){
            var $=layui.jquery,table=layui.table,laydate = layui.laydate,
                layer = layui.layer,form = layui.form,util=layui.util;

            form.on('submit(save)',function(data){
                $.ajax({
                    url:"/manage/redis/datas",
                    type:"post",
                    dataType:"json",
                    data:data.field,
                    success:function(res){
                        if(res.code==0){
                            $(".dataitem").remove();
                            showData(res.data);
                        }
                    }
                })
                return false;
            })

            $(".layui-input").keydown(function (e) {
                if(e.keyCode == 13){
                    $('#search').click();
                }
            });

            function showData(data) {
                var div = '';
                if(data){
                    div += '<div class="layui-form-item dataitem"><pre style="border: 1px solid #5FB878;padding: 20px;">'
                    if(data.indexOf("[") != -1 || data.indexOf("}") != -1){
                        div += JSON.stringify(JSON.parse(data),null,2);
                    }else{
                        var res = '';
                        if(data instanceof Array){  //判断是否是数组
                            for(var i =0; i < data.length;i++ ){
                                res += data[i] + '<br/>';
                            }
                            div += res;
                        }else{
                            div += data;
                        }
                    }
                    div += '</pre></div>';
                }
                $("#key").after(div);
            }
        });
    </script>
</div>
</body>
</html>